找传奇、传世资源到传世资源站!

单片机控制led(12864(2).C)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

#include <reg51.h>#include <intrins.h>typedef unsigned char u8;typedef unsigned int u16;sbit RS=P2^7;sbit RW=P2^6;sbit E=P2^5;sbit PSB=P2^4;sbit RES=P2^2;u8 code datas1[] = {"我爱中国"};u8 code datas2[] = {"电子1901"};u8 code datas3[] = {"108-08"};u8 code datas4[] = {"宋涛"};void delayUs(){ _nop_();_nop_();}void delayMs(u16 a){ u16 i, j; for(i = a; i > 0; i--) for(j = 100; j > 0; j--);}bit checkBusy(){ bit busy; RS= 0; RW = 1; E = 1; delayUs(); busy = (bit)(P0&0x80); E = 0; return busy;}void wait(){ while(checkBusy());}void writeCmd(u8 cmd){ wait(); RS = 0; RW = 0; E = 0; delayUs(); P0 = cmd; delayUs(); E = 1; delayUs(); E = 0;}void writeData(u8 dat){ wait(); RS = 1; RW = 0; E = 0; delayUs(); P0 = dat; delayUs(); E = 1; delayUs(); E = 0;}void init(){ delayUs(); PSB=1; delayUs(); RES=0; delayUs(); RES=1; delayUs(); writeCmd(0x30); delayMs(10); writeCmd(0x0c); delayMs(10); writeCmd(0x01); delayMs(10);}void setPosition(u8 x, u8 y){ u8 addr;if(x==0){addr=0x80 y;}elseif(x==1){ addr=0x90 y;}elseif(x==2){addr=0x88 y;}elseif(x==3){addr=0x98 y;}addr =y; writeCmd(addr);}void writeString(u8 *str){ u8 i = 0; while(str[i] != '\0') { writeData(str[i ]); }}void main(){ init(); setPosition(0, 0); writeString(datas1); setPosition(1, 0); writeString(datas2); setPosition(2, 0); writeString(datas3); setPosition(3, 0); writeString(datas4); while(1);}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复